﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ControllerBase
{
    /// <summary>
    /// 这里是初始化操作，返回坦克的基本参数
    /// </summary>
    /// <returns></returns>
    public virtual PlayerData GetPlayerData()
    {
        return new PlayerData()
        {
            Name = "基类",
            Author = "System",
            BaseImage = "Sprite/Base/Base01",
            GunImage = "Sprite/Gun/Gun01"
        };
    }

    /// <summary>
    ///  用于协程的类，也就是Player
    /// </summary>
    public MonoBehaviour CoroutineMono;

    /// <summary>
    /// 玩家信息类
    /// </summary>
    public PlayerObject Data;

    public void SetAction(MonoBehaviour coroutineMono,
        PlayerObject data,
        Action<float, float, float> move,
        Action<float, Vector3> moveTo,
        Action<float, float> turn,
        Action<float, Vector3> turnTo,
        Action stop,
        Action<int, int> fire,
        Action stopTurn,
        Action ceaseFire,
        Action<string, float> talk)
    {
        CoroutineMono = coroutineMono;
        Data = data;
        Move = move;
        MoveTo = moveTo;
        Turn = turn;
        TurnTo = turnTo;
        Stop = stop;
        Fire = fire;
        StopTurn = stopTurn;
        CeaseFire = ceaseFire;
        Talk = talk;
    }

    //基本操作的委托
    /// <summary>
    /// 前进到位置 参数 速度、坐标
    /// </summary>
    protected Action<float, Vector3> MoveTo { get; private set; }

    /// <summary>
    /// 前进 参数 速度、方向、时间
    /// </summary>
    protected Action<float, float, float> Move { get; private set; }

    /// <summary>
    /// 转炮 参数 目标角度、转速（正数是逆时针）
    /// </summary>
    protected Action<float, float> Turn { get; private set; }

    /// <summary>
    /// 转炮对准目标 参数 转速（正数是逆时针）、目标位置
    /// </summary>
    protected Action<float, Vector3> TurnTo { get; private set; }

    /// <summary>
    /// 刹车
    /// </summary>
    protected Action Stop { get; private set; }

    /// <summary>
    /// 开火 参数 数量、能量
    /// </summary
    protected Action<int, int> Fire { get; private set; }

    /// <summary>
    /// 停止转炮
    /// </summary>
    protected Action StopTurn { get; private set; }

    /// <summary>
    /// 停火
    /// </summary>
    protected Action CeaseFire { get; private set; }

    /// <summary>
    /// 聊天  参数 内容、持续时间
    /// </summary>
    protected Action<string, float> Talk { get; private set; }

    public virtual void Start()
    {
    }

    public virtual IEnumerator LoopAction()
    {
        yield return 0;
    }

    public virtual void OnCrashWall()
    {
    }

    public virtual void OnCrashOthers(Vector3 othersPosition, float othersSpeed)
    {
    }

    public virtual void OnHitted(float bulletAngle)
    {
    }

    public virtual void OnScanOthers(ScanOthersData scanOthersData)
    {
    }

    public virtual void OnScaned(float angle)
    {
    }

    public virtual void Update()
    {
    }
}

public class PlayerData
{
    /// <summary>
    /// 坦克名称
    /// </summary>
    public string Name;

    /// <summary>
    /// 作者
    /// </summary>
    public string Author;

    /// <summary>
    /// 基座图
    /// </summary>
    public string BaseImage;

    /// <summary>
    /// 炮台图
    /// </summary>
    public string GunImage;
}

public class ScanOthersData
{
    public bool IsEnemy;
    public Vector2 othersPosition;
    public float othersAngle;
    public Vector2 othersSpeed;
}